import WorkflowDivi from '@/components/page/WorkflowDivi';
import { format } from '@/utils/datetime';
import { renderNumber } from '@/utils/common';
import { useModel } from 'umi';
export default () => {
  const { props } = useModel('sysInfo', (ret) => ({
    props: ret.getCurExtendProps(),
  }));
  const taskColumns: API.Column[] = [
    {
      title: '申请人',
      dataIndex: 'SQR',
      key: 'SQR',
      width: 120,
      sorter: true,
      dispaly: true,
      filter: true,
      export: true,
      dataType: 'string',
    },
    {
      title: '申请时间',
      key: 'SQDT',
      render: (data) => format(data, 'yyyy-MM-dd'),
      width: 120,
      sorter: true,
      dispaly: true,
      filter: true,
      dataType: 'date',
    },
    {
      title: '客户名称',
      dataIndex: 'CUNM',
      key: 'CUNM',
      width: 220,
      sorter: true,
      dispaly: true,
      filter: true,
      dataType: 'string',
    },
    {
      title: '证件号码',
      dataIndex: 'IDNO',
      key: 'IDNO',
      width: 180,
      sorter: true,
      dispaly: true,
      filter: true,
      export: true,
      dataType: 'string',
    },
    {
      title: '借据编号',
      dataIndex: 'EVNO',
      key: 'EVNO',
      width: 180,
      sorter: true,
      dispaly: true,
      filter: true,
      dataType: 'string',
    },
    {
      title: '开户网点',
      dataIndex: 'UTNM',
      key: 'UTNM',
      width: 120,
      sorter: true,
      dispaly: true,
      filter: true,
      export: true,
      dataType: 'string',
    },
    {
      title: '业务品种',
      dataIndex: 'LAKD',
      key: 'LAKD',
      width: 120,
      sorter: true,
      dispaly: true,
      filter: true,
      export: true,
      dataType: 'string',
    },
    {
      title: props.isUpdate ? '变更日期' : '开户日期',
      key: props.isUpdate ? 'DSDT' : 'OPDT',
      dataIndex: props.isUpdate ? 'DSDT' : 'OPDT',
      render: (data) => format(data, 'yyyy-MM-dd'),
      width: 110,
      sorter: true,
      dispaly: true,
      export: true,
      dataType: 'date',
    },
  ];
  const importControls: API.Control[] = [
    {
      name: 'CUNM',
      type: 'text',
      label: '客户名称',
      dataType: 'string',
      grid: 12 / 24,
      rules: [{ required: true, message: '客户名称不能为空' }],
    },
    {
      name: 'EVNO',
      type: 'text',
      label: '借据编号',
      dataType: 'string',
      grid: 12 / 24,
      rules: [{ required: true, message: '借据编号不能为空' }],
    },
  ];

  if (props.isUpdate) {
    importControls.push({
      name: 'DSDT',
      type: 'date',
      label: '变更日期',
      dataType: 'date',
      grid: 12 / 24,
      rules: [{ required: true, message: '变更日期不能为空' }],
    });
  }
  const renderDivi = (divis: Record<string, any>[]) => {
    if (!divis || divis.length == 0) {
      return '';
    }
    let diviStr = '';
    divis.map((d) => {
      diviStr = diviStr + d.EMNM + '(' + d.EMNO + '):' + d.DSVL + ' ';
    });
    return diviStr;
  };
  const searchColumns: API.Column[] = [
    {
      title: '借据编号',
      dataIndex: 'EVNO',
      key: 'EVNO',
      width: 220,
      sorter: true,
      dispaly: true,
      filter: true,
      fixed: 'left',
      ellipsis: true,
      dataType: 'string',
    },
    {
      title: '客户名称',
      dataIndex: 'CUNM',
      key: 'CUNM',
      width: 220,
      sorter: true,
      dispaly: true,
      filter: true,
      ellipsis: true,
      dataType: 'string',
    },
    {
      title: '证件号码',
      dataIndex: 'IDNO',
      key: 'IDNO',
      width: 180,
      sorter: true,
      dispaly: true,
      filter: true,
      export: true,
      dataType: 'string',
    },
    {
      title: '开户网点',
      dataIndex: 'UTNM',
      key: 'UTNM',
      width: 130,
      sorter: true,
      dispaly: true,
      filter: true,
      dataType: 'string',
    },
    {
      title: '业务品种',
      dataIndex: 'LAKD',
      key: 'LAKD',
      width: 130,
      sorter: true,
      dispaly: true,
      filter: true,
      ellipsis: true,
      dataType: 'string',
    },
    {
      title: '发放日期',
      key: 'Releasedate',
      dataIndex: 'Releasedate',
      render: (data) => format(data, 'yyyy-MM-dd'),
      width: 140,
      sorter: true,
      dispaly: true,
      filter: true,
      dataType: 'date',
    },
    {
      title: '到期日期',
      dataIndex: 'Maturitydate',
      key: 'Maturitydate',
      render: (date) => format(date, 'yyyy-MM-dd'),
      width: 120,
      sorter: true,
      dispaly: true,
      filter: true,
      dataType: 'date',
    },
    {
      title: '余额',
      dataIndex: 'ACBL',
      key: 'ACBL',
      render: (acbl) => renderNumber('.0f', acbl),
      width: 130,
      sorter: true,
      dispaly: true,
      filter: true,
      dataType: 'number',
    },
  ];
  if (props.isUpdate) {
    searchColumns.push({
      title: '原客户经理',
      dataIndex: 'Bgqdivi',
      key: 'Bgqdivi',
      render: (divis) => renderDivi(divis),
      width: 180,
      dispaly: true,
      ellipsis: true,
    });
  }
  const importName = props.isUpdate ? 'IndiLoanWorkflowUpdateApp' : 'IndiLoanWorkflowNewApp';
  const taskDaoName = props.isUpdate ? 'IndiLoanWorkflowUpdateApp' : 'IndiLoanWorkflowNewApp';
  const searchDaoName = props.isUpdate ? 'IndiLoanFlowChUpdate' : 'IndiLoanFlowChNew';
  const importTemplateName = props.isUpdate ? '个贷关联变更申请' : '个贷新户关联申请';
  const title =
    (props.isUpdate ? '个贷关联变更' : '个贷新户关联') +
    (props.showType === 'apply' ? '申请' : '审批');
  const searchControls: API.Control[] = [
    {
      name: 'CUNM',
      type: 'text',
      label: '客户',
      grid: 12 / 24,
      width: 100,
      layout: { labelSpan: 8, wrapperSpan: 16 },
      placeholder: '请输入完整的客户名称...',
      rules: [{ required: true, message: '客户不能为空' }],
    },
    {
      name: 'IDNO',
      type: 'text',
      label: '证件号码',
      grid: 12 / 24,
      width: 200,
      layout: { labelSpan: 8, wrapperSpan: 16 },
      placeholder: '请输入完整的证件号码...',
      rules: [{ required: true, message: '客户不能为空' }],
    },
  ];
  return (
    <WorkflowDivi
      taskDaoName={taskDaoName}
      taskColumns={taskColumns}
      searchDaoName={searchDaoName}
      searchColumns={searchColumns}
      importName={importName}
      importTemplateName={importTemplateName}
      importControls={importControls}
      titleColNames={['CUNM', 'EVNO']}
      searchControls={searchControls}
      searchKeyColName="ACID"
      maxEmplCount={2}
      title={title}
      subhead="*为必输项"
      showType={props.showType}
      isUpdate={props.isUpdate}
      userIsFirstEmpl={true}
    />
  );
};
